const App = {
    extends: Parent,
    methods: {
        init() {
            this.selectMyUser();
        },
        addCommunityMember(communityId) {
            axios.post(ParentUrl+"/CommunityMember/"+communityId).then(resp=>{
                this.Result = resp.data;
                if(this.Result.code === 1) {
                    this.$message({
                        message: '成功加入！',
                        type: 'success'
                    });
                } else {
                    this.$message({
                        message: '加入失败！',
                        type: 'warning'
                    });
                }
            });
        },//加入社区成员
        search() {
            this.searchUser();
            this.searchCommunity();
            this.searchTrends();
        },//搜素
        searchUser() {
            axios.get(ParentUrl+"/User?username="+this.searchContent).then(resp=>{
                this.Result = resp.data;
                if(this.Result.code === 1) {
                    this.users = this.Result.data;
                } else {
                }
            });
        },//搜素用户
        searchCommunity() {
            axios.get(ParentUrl+"/Community/3?name="+this.searchContent).then(resp=>{
                this.Result = resp.data;
                if(this.Result.code === 1) {
                    this.communities = this.Result.data;
                } else {
                }
            });
        },//搜素社区
        searchTrends() {
            var _this = this;
            axios({
                method:"get",
                url:ParentUrl+"/Trends/4?title="+_this.searchContent
            }).then(resp => {
                _this.Result = resp.data;
                if(_this.Result.code === 1) {
                    _this.trends = _this.Result.data;
                } else {

                }
            })
        },//搜素动态
        selectCommunity(name) {
            var _this = this;
            axios.get(ParentUrl+"/Community/"+name).then(resp=>{
                _this.Result = resp.data;
                if(_this.Result.code===1) {
                    _this.hCommunity = _this.Result.data;
                }
                else {
                }
            });
        },//查询社区
        searchTrendsByCommunity(name) {
            var _this = this;
            axios({
                method:"get",
                url:ParentUrl+"/Trends/5?name="+name
            }).then(resp => {
                _this.Result = resp.data;
                if(_this.Result.code === 1) {
                    _this.communityTab.title = name;
                    _this.communityTab.trends=_this.Result.data;
                    _this.tabIndex='2';
                } else {

                }
            })
        },//查询社区动态
        selectCritique(trendsId) {
            var _this = this;
            axios.get(ParentUrl+"/Critique/"+trendsId).then(resp=>{
                _this.Result = resp.data;
                if(_this.Result.code===1) {
                    _this.critiques = _this.Result.data;
                }
                else {
                    _this.critiques = null;
                }
            });
        },//查询评论
        //点赞
        like(trend) {
            var _this = this;
            axios.put(ParentUrl+"/Trends/1/"+trend.id).then(resp=>{
                _this.Result = resp.data;
                //成功点赞
                if (_this.Result.code===1) {
                    this.$message({
                        message: '点赞成功！',
                        type: 'success'
                    });
                    trend.likesNum++;
                }
                //取消点赞
                else if (_this.Result.code===-1) {
                    this.$message({
                        message: '已取消点赞。',
                        type: 'success'
                    });
                    trend.likesNum--;
                }
                //点赞失败
                else {
                    this.$message({
                        message: '点赞失败！',
                        type: 'warning'
                    });
                }
            });
        },
        //收藏
        collect(trend) {
            var _this = this;
            axios.put(ParentUrl+"/Trends/2/"+trend.id).then(resp=>{
                _this.Result = resp.data;
                //成功点赞
                if (_this.Result.code===1) {
                    this.$message({
                        message: '收藏成功！',
                        type: 'success'
                    });
                    trend.collectNum++;
                }
                //取消点赞
                else if (_this.Result.code===-1) {
                    this.$message({
                        message: '已取消收藏。',
                        type: 'success'
                    });
                    trend.collectNum--;
                }
                //点赞失败
                else {
                    this.$message({
                        message: '收藏失败！',
                        type: 'warning'
                    });
                }
            });
        },
        critiqueTrends() {
            var _this = this;
            axios.post(ParentUrl+"/Critique", _this.critique).then(resp=>{
                _this.Result = resp.data;
                if(_this.Result.code===1) {
                    _this.critiques=null;
                    _this.critiqueDialog = false;
                    this.$message({
                        showClose: true,
                        message: '评论成功！',
                        type: 'success'
                    });
                } else {
                    this.$message({
                        showClose: true,
                        message: '评论失败！',
                        type: 'warning'
                    });
                }
            })
        }//评论
    },
    data() {
        return {
            activeIndex: '4',//标题栏高显位置
            searchContent: '',//搜素内容
            trendsDialog: false,//查看全部
            critiqueDialog: false,//评论
            userInformationDialog: false,//查看用户
            communityInformationDialog: false,//查看社区
            users: [],//搜素用户
            communities: [],//搜素社区
            //搜素动态
            trends: [],
            //查看全部动态
            hTrend: {},
            hCommunity: {},//查看社区
            //动态评论
            critiques: [],
            //当前评论
            critique: {
                content: '',
                time: date.toLocaleDateString()+'/'+date.toLocaleTimeString(),
                trendsId: ''
            },
            tabIndex: '1',//标签页下标
            communityTab: {
                title: '空白',
                trends: []
            }//社区动态
        }
    }
}
const app = Vue.createApp(App);
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
    app.component(key, component)
}
app.use(ElementPlus);
app.mount("#app");